<template>
	<view>
		<view class="balance">
			<view class="balance-value">{{moneyFormat(memberInfo.accountBalance)}}</view>
			<view class="balance-label">账户余额</view>
		</view>
		<view class="custom-form">
			<uv-form label-position="top" label-width="150">
				<uv-form-item label="转账金额">
					<uv-input placeholder="请输入" v-model="amount" type="number" :clearable="false">
						<template v-slot:suffix>
							<uv-button type="primary" text="全部" size="mini" @click="allAmount"></uv-button>
						</template>
					</uv-input>

				</uv-form-item>
				<uv-form-item label="对方账号">
					<uv-input placeholder="请输入" v-model="transferInAccount" :clearable="false"></uv-input>
				</uv-form-item>
				<uv-form-item label="支付密码">
					<uv-input placeholder="请输入" v-model="payPwd" :clearable="false" :password="true"></uv-input>
				</uv-form-item>
			</uv-form>
		</view>
		<view class="fixed-bottom">
			<view class="fixed-bottom-inner">
				<uv-button type="primary" text="立即转账" size="large" @click="transfer"></uv-button>
			</view>
		</view>

	</view>
</template>

<script>
	import common from '@/common/common'
	export default {
		data() {
			return {
				amount: '',
				transferInAccount: '',
				payPwd: '',
				memberInfo: '',
			}
		},
		onLoad(option) {
			this.getMemberInfo();
		},
		methods: {

			allAmount() {
				this.amount = this.memberInfo.accountBalance;
			},

			transfer() {
				var that = this;
				if (that.amount == null || that.amount == '') {
					uni.showToast({
						title: "请输入转账金额",
						icon: "none"
					});
					return;
				}
				if (that.transferInAccount == null || that.transferInAccount == '') {
					uni.showToast({
						title: "请输入对方账号",
						icon: "none"
					});
					return;
				}
				if (that.payPwd == null || that.payPwd == '') {
					uni.showToast({
						title: "请输入支付密码",
						icon: "none"
					});
					return;
				}
				uni.$uv.http.post('/memberTransfer/transfer', {
					amount: that.amount,
					transferInAccount: that.transferInAccount,
					payPwd: that.payPwd,
				}).then(res => {
					uni.showToast({
						icon: 'success',
						title: '操作成功',
						duration: 2000,
						complete: function() {
							setTimeout(() => {
								uni.reLaunch({
									url: "../my/my"
								});
							}, 2000);
						}
					});
				});
			},

			getMemberInfo() {
				var that = this;
				uni.$uv.http.get('/member/getMemberInfo').then(res => {
					that.memberInfo = res.data;
				});
			},

			moneyFormat(amount) {
				return common.moneyFormat(amount);
			},
		}
	}
</script>

<style>
	.custom-form {
		padding-left: 32rpx;
		padding-right: 32rpx;
	}

	.balance-value {
		font-size: 52rpx;
		font-weight: 700;
		color: #fff;
		margin-bottom: 24rpx;
	}

	.balance-label {
		font-size: 28rpx;
		font-weight: bold;
		color: #fff;
	}

	.balance {
		background: linear-gradient(127deg, #0068b7 10%, #b9d4e9);
		text-align: center;
		padding: 64rpx;
	}
</style>